﻿<%@ Page Title="" Language="C#" MasterPageFile="~/TsSite.Master" AutoEventWireup="true" CodeBehind="ServiceCarGeoAreaAllocationList.aspx.cs" Inherits="TireService.Web.View.ResourceView.ServiceCarGeoAreaAllocationList" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallbackPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxPivotGrid.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxPivotGrid" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxSplitter" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>


<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <!-- Javascript -->
    <script language="javascript" type="text/javascript">

        function ShowCreateServiceCarGeoAreaAllocation(Dropdown) {
            // Show create modal popup
            pcCreateServiceCarGeoAreaAllocation.Show();

            // Perform callback based on selected servicecar
            callbackCreateServiceCarGeoAreaAllocationPanel.PerformCallback(Dropdown.GetValue());
        }

        function DeleteServiceCarGeoAreaAllocation(id) {

            var answer = confirm("Slet tildelt område fra servicebil?")
            if (answer) {
                // Run callback function to delete record
                callDeleteServiceCarGeoAreaAllocation.PerformCallback(id);
            }
        }

        function UpdateServiceCarAreaAllocation(ServiceCarScheduleId, Checkbox) {

            var input = ServiceCarScheduleId + '|' + Checkbox.GetChecked() + '|' + ddlServiceGeographicalArea.GetValue();

            callbackUpdateServiceCarAreaAllocation.PerformCallback(input);
        }

        function OnCallbackCreateServiceCarGeoAreaAllocationComplete() {

            // Nothing
        }

        function OnCallbackDeleteServiceCarGeoAreaAllocationComplete() {

            gvServiceCarGeoAreaAllocation.PerformCallback();
        }

        function OnCallbackUpdateServiceCarAreaAllocationComplete() {

            gvAvailableScheduleDates.PerformCallback();
        }
       

        function CallBackError(s, e) {
            alert('Fejl opstod: ' + e.message);
        }

    </script>


    <table>
        <tr>
            <td>
                <dx:ASPxDateEdit ID="txtSelectedStartDate" ClientInstanceName="txtSelectedStartDate" runat="server">
                    <ClientSideEvents DateChanged="function(s, e) { gvServiceCarGeoAreaAllocation.PerformCallback()  }" />
                </dx:ASPxDateEdit>
            </td>
            <td>
                <dx:ASPxDateEdit ID="txtSelectedEndDate" ClientInstanceName="txtSelectedEndDate" runat="server">
                    <ClientSideEvents DateChanged="function(s, e) { gvServiceCarGeoAreaAllocation.PerformCallback()  }" />
                </dx:ASPxDateEdit>
            </td>
            <td>
                <dx:ASPxComboBox ID="ddlServiceCar" ClientInstanceName="ddlServiceCar" runat="server">
                    <ClientSideEvents SelectedIndexChanged="function(s, e) { gvServiceCarGeoAreaAllocation.PerformCallback() }" />
                </dx:ASPxComboBox>
            </td>
            <td>
                <dx:ASPxButton ID="btnAreaToServiceCar" ClientInstanceName="btnAreaToServiceCar" runat="server" Text="Tildel områder" AutoPostBack="False" UseSubmitBehavior="False">
                    <ClientSideEvents Click="function(s, e) { ShowCreateServiceCarGeoAreaAllocation(ddlServiceCar) }" />
                </dx:ASPxButton>
            </td>
        </tr>
    </table>

    <dx:ASPxCallback ID="callDeleteServiceCarGeoAreaAllocation" ClientInstanceName="callDeleteServiceCarGeoAreaAllocation" runat="server" OnCallback="callDeleteServiceCarGeoAreaAllocation_Callback">
        <ClientSideEvents CallbackError="CallBackError" CallbackComplete="OnCallbackDeleteServiceCarGeoAreaAllocationComplete" />
    </dx:ASPxCallback>

    <hr />
    <dx:ASPxGridView ID="gvServiceCarGeoAreaAllocation" runat="server" Caption="Områder allokeret til servicebil" 
        ClientInstanceName="gvServiceCarGeoAreaAllocation" Width="100%" KeyFieldName="ServiceCarAreaAllocationId" AutoGenerateColumns="False" EnableCallBacks="True"
        OnCustomCallback="gvServiceCarGeoAreaAllocation_CustomCallback">
        <SettingsLoadingPanel Text="Henter&amp;hellip;" />
        <Border BorderWidth="0px" />
        <Settings ShowHeaderFilterButton="true" ShowGroupPanel="false" ShowFilterRow="true" />
        <SettingsPager AlwaysShowPager="False" PageSize="10" Position="Bottom">
            <Summary 
                AllPagesText="Sider: {0} - {1} ({2} område tildelinger)" 
                Text="Side {0} af {1} ({2} område tildelinger)" />
        </SettingsPager>
        <SettingsBehavior ProcessFocusedRowChangedOnServer="false" AllowFocusedRow="true" ConfirmDelete="True" AllowGroup="false" AllowDragDrop="false" />
        <Columns>
            <dx:GridViewDataColumn VisibleIndex="0">
                <DataItemTemplate>
                    <dx:ASPxButton ID="btnDeleteServiceCarGeoAreaAllocation" runat="server" Text="Slet" ToolTip="Klik for at slette tildelt område til servicebil" AutoPostBack="false"
                        ClientSideEvents-Click='<%# "function(s, e) { DeleteServiceCarGeoAreaAllocation(" + Container.KeyValue + "); }" %>'>
                    </dx:ASPxButton>                                          
                </DataItemTemplate>
            </dx:GridViewDataColumn>
            <dx:GridViewDataTextColumn FieldName="ScheduleDate" Caption="Dato" VisibleIndex="0" />
            <dx:GridViewDataTextColumn FieldName="AreaDescription" Caption="Område" VisibleIndex="1" />
            <%--<dx:GridViewDataTextColumn FieldName="Capacity" Caption="Kapacitet" VisibleIndex="2" />
            <dx:GridViewDataTextColumn FieldName="AvailableCapacity" Caption="Ledig kapacitet" VisibleIndex="3" />--%>
        </Columns>
    </dx:ASPxGridView>
    
    <!-- Modalpopup: Assign GeoArea to servicecar -->
    <dx:ASPxPopupControl ID="pcCreateServiceCarGeoAreaAllocation" Modal="true" runat="server" Height="1px" AutoUpdatePosition="true"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter"
        AllowDragging="True" ClientInstanceName="pcCreateServiceCarGeoAreaAllocation" Left="100" Top="100"
        CloseAction="CloseButton" Width="250px" HeaderText="Opret område allokering">
        <ClientSideEvents Closing="function(s, e) { gvServiceCarGeoAreaAllocation.PerformCallback() }" />
        <ContentCollection>
            <dx:PopupControlContentControl ID="PopupControlContentControl1" runat="server">
                <dx:ASPxCallbackPanel ID="callbackCreateServiceCarGeoAreaAllocationPanel" ClientInstanceName="callbackCreateServiceCarGeoAreaAllocationPanel" runat="server"
                    Width="450px" Height="100px" OnCallback="callbackCreateServiceCarGeoAreaAllocationPanel_Callback" RenderMode="Table">
                    <ClientSideEvents EndCallback="OnCallbackCreateServiceCarGeoAreaAllocationComplete" CallbackError="CallBackError" />
                    <PanelCollection>
                        <dx:PanelContent ID="PanelContent1" runat="server">
                            <dx:ASPxComboBox ID="ddlServiceGeographicalArea" ClientInstanceName="ddlServiceGeographicalArea" runat="server">
                                <ClientSideEvents SelectedIndexChanged="function(s, e) { gvServiceCarGeoAreaAllocation.PerformCallback() }" />
                            </dx:ASPxComboBox>
                            <dx:ASPxGridView ID="gvAvailableScheduleDates" runat="server" Caption="Ikke allokeret datoer" 
                                ClientInstanceName="gvAvailableScheduleDates" Width="100%" KeyFieldName="ServiceCarScheduleId" AutoGenerateColumns="False" EnableCallBacks="True"
                                OnCustomCallback="gvAvailableScheduleDates_CustomCallback">
                                <SettingsLoadingPanel Text="Henter&amp;hellip;" />
                                <Border BorderWidth="0px" />
                                <Settings ShowHeaderFilterButton="false" ShowGroupPanel="false" ShowFilterRow="false" ShowPreview="true" />
                                <SettingsPager AlwaysShowPager="False" PageSize="10" Position="Bottom">
                                    <Summary 
                                        AllPagesText="Sider: {0} - {1} ({2} ikke allokeret datoer)" 
                                        Text="Side {0} af {1} ({2} ikke allokeret datoer)" />
                                </SettingsPager>
                                <SettingsBehavior ProcessFocusedRowChangedOnServer="false" AllowFocusedRow="true" ConfirmDelete="True" AllowGroup="false" AllowDragDrop="false" />
                                <Columns>
                                    <dx:GridViewDataTextColumn FieldName="ScheduleDate" Caption="Dato" VisibleIndex="0" />
                                    <dx:GridViewDataColumn VisibleIndex="1" Caption="Allokeret">
                                        <DataItemTemplate>
                                            <dx:ASPxCheckBox ID="cbAreaAllocation" Checked='<%# Eval("AreaAllocated") %>' runat="server" ClientSideEvents-CheckedChanged='<%# "function(s, e) { UpdateServiceCarAreaAllocation(" + Container.KeyValue + ", s); }" %>'>
                                            </dx:ASPxCheckBox>                                 
                                        </DataItemTemplate>
                                    </dx:GridViewDataColumn>
                                    <dx:GridViewDataTextColumn FieldName="AreaDescription" Caption="Dato" VisibleIndex="2" />
                                    <dx:GridViewDataTextColumn FieldName="Capacity" Caption="Kapacitet" VisibleIndex="3" />
                                    <dx:GridViewDataTextColumn FieldName="AvailableCapacity" Caption="Ledig kapacitet" VisibleIndex="4" />
                                </Columns>
                                <%--<Templates>
                                    <PreviewRow>
                                        <table>
                                            <tr>
                                                <td>
                                                    <dx:ASPxLabel ID="lblScheduleDate" runat="server" Text='<%# Eval("ScheduleDate") %>'>
                                                    </dx:ASPxLabel>
                                                </td>
                                                <td>
                                                    
                                                </td>
                                                <td>
                                                    <dx:ASPxLabel ID="ASPxLabel1" runat="server" Text='<%# Eval("AreaDescription") %>'>
                                                    </dx:ASPxLabel>
                                                </td>
                                                <td>
                                                    <dx:ASPxLabel ID="ASPxLabel2" runat="server" Text='<%# Eval("Capacity") %>'>
                                                    </dx:ASPxLabel>
                                                </td>
                                                <td>
                                                    <dx:ASPxLabel ID="ASPxLabel3" runat="server" Text='<%# Eval("AvailableCapacity") %>'>
                                                    </dx:ASPxLabel>
                                                </td>
                                            </tr>
                                        </table>
                                    </PreviewRow>
                                </Templates>--%>
                            </dx:ASPxGridView>

                        </dx:PanelContent>
                    </PanelCollection>
                </dx:ASPxCallbackPanel>
            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>

    <dx:ASPxCallback ID="callbackUpdateServiceCarAreaAllocation" ClientInstanceName="callbackUpdateServiceCarAreaAllocation" runat="server" OnCallback="callbackUpdateServiceCarAreaAllocation_Callback">
        <ClientSideEvents CallbackError="CallBackError" CallbackComplete="OnCallbackUpdateServiceCarAreaAllocationComplete" />
    </dx:ASPxCallback>

</asp:Content>
